#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>

#define MAX_STR_LEN 65536

char *get_string()
{
	//TODO aggiungere '\0' a fine lettura
	return "stringadiprova_stringahz";
}

struct triple {
	uint16_t o;
	uint16_t l;
	char a;
};

struct triple *encode(char raw[], int *t_i)
{

	//worst case 1 char -> 1 struct
	static struct triple encoded[MAX_STR_LEN];
	int tr_ind = 0;

	int str_len = strlen(raw);

	//(o,l,a)
	uint16_t temp_o,temp_l;
	char temp_a;
 
	//parsing input string
	for(int i = 0; i < str_len; i++){
		encoded[tr_ind].o = 0;
		encoded[tr_ind].l = 0;
		encoded[tr_ind].a = raw[i];
 
		temp_l = 0;
		//looping every offset
		for(int j = 1; j <= i; j++){
			//length
			while(i+temp_l+1 < str_len){

				if(raw[i+temp_l] == raw[i-j+temp_l]){
					temp_o = j;
					++temp_l;
					temp_a = raw[i+temp_l];
				}
				else
					break;
		}
	}

	if(temp_l > encoded[tr_ind].l){
		encoded[tr_ind].o = temp_o;
		encoded[tr_ind].l = temp_l;
		encoded[tr_ind].a = temp_a;
	}
 
	printf("(%u,%u,%c)\n", encoded[tr_ind].o, encoded[tr_ind].l, encoded[tr_ind].a);
	i += encoded[tr_ind].l;
	++tr_ind;
}
 	*t_i = tr_ind;
	return encoded;
}

int main()
{
	int tr_ind;
	encode(get_string(), &tr_ind);
}
